package com.yanqu.road.server.cmd.vehicle;

import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/10/13 14:44
 */
@Cmd(code = GameProtocol.S_GIVE_UP_VEHICLE_RANDOM_SKILL, desc = "放弃替换珍兽改装技能")
public class GiveUpRandomSkillCmd extends AbstractCommand {
    private String vehicleUid;
    private int pos;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VehicleProto.GiveUpRandomSkillReqMsg msg = VehicleProto.GiveUpRandomSkillReqMsg.parseFrom(packet.getBytes());
        vehicleUid = msg.getVehicleUid();
        pos = msg.getSkillPos();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(VehicleModule.class).giveUpRandomSkill(vehicleUid, pos);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            VehicleProto.GiveUpRandomSkillRespMsg.Builder respMsg = VehicleProto.GiveUpRandomSkillRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_GIVE_UP_VEHICLE_RANDOM_SKILL, respMsg);
        }
    }
}
